<?php

namespace Gnway\Ticket\Rest\Annotation;

use Doctrine\Common\Annotations\Annotation\Target;
use Doctrine\Common\Annotations\Annotation\Attribute;
use Doctrine\Common\Annotations\Annotation\Attributes;
use RuntimeException;

/**
 * MappingScan Annotation
 *
 * @Annotation
 * @Target("CLASS")
 * @Attributes({
 *     @Attribute("file", type="string", required=false),
 * })
 * @author zushaolong
 * @mail zushaolong@gmail.com
 */
final class MappingScan
{

  /**
   * Mapping file
   *
   * @var string
   */
  private string $file = '';

  /**
   * MappingScan constructor.
   *
   * @param array $values
   */
  public function __construct(array $values)
  {
    $file = $values['file'] ?? $values['value'];
    if ($file && !is_file($file = realpath($file))) {
      throw new RuntimeException('Attribute "file" of @MappingScan must be a file');
    }
    $this->file = (string)$file;
  }

  /**
   * @return string
   */
  public function getFile(): string
  {
    return $this->file;
  }
}